#include "Process.h"
#include "../Language/Interface.h"

CProcess::CProcess(string imageCode, HANDLE userThread) : CThreadObject()
{
	_processState = luaL_newstate();
	if(_processState)
	{
		/* call api registration */
		API_InitializeProcess(_processState, userThread, (HANDLE)(void*)this);

		/* startup the core api for this process */

		int result = luaL_dostring(_processState, os_LoadFile("core","core.library").c_str());
		if(result) {
			cout<<"error:"<<lua_tostring(_processState,-1)<<endl;
			cout<<endl<<"code:"<<endl<<endl;
			cout<<os_LoadFile("core","core.library")<<endl;
		}

		/* now run the image passed to this process */

		result = luaL_dostring(_processState, imageCode.c_str());
		if(result) {
			cout<<"error:"<<lua_tostring(_processState,-1)<<endl;
			cout<<endl<<"code:"<<endl<<endl;
			cout<<imageCode.c_str()<<endl;
		}
	}
}

CProcess::~CProcess()
{

}

void CProcess::InitThread()
{

}

void CProcess::FlushThread()
{

}

void CProcess::Run()
{
	while(true)
	{

	}
}